package com.zwb.service.common;

import com.zwb.service.pojo.Admin;
import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.security.core.context.SecurityContextHolder;

import java.lang.reflect.Method;

/**
 * @author 头发又黑又长
 * @Date 2022/8/31 20:10
 * @email zwb15083976291@163.com
 */

public class UserIdKeyGenerator implements KeyGenerator {
    @Override
    public Object generate(Object target, Method method, Object... params) {
        Admin principal = (Admin) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        return method.getName() + ":userid:" + principal.getId();
    }
}
